
package com.hlkj.pay.service;/*
                             * Hlpay-Plus aggregate payment system.
                             * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
                             
                             */

import com.hlkj.framework.common.pojo.LocalContext;
import com.hlkj.framework.common.pojo.LocalRequest;
import com.hlkj.pay.dto.BaseQueryDto;
import com.hlkj.pay.dto.LocalAdminUserRequest;
import com.hlkj.pay.dto.LocalMerchantRequest;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

/**
 * @author HlpayTeam
 * @date 2024/09/10 14:42
 */
public class CommonSnFilterService {

    public void filterSn(BaseQueryDto baseQueryDto) {
        if(!baseQueryDto.isFilterSn()){
            return;
        }
        if (!StringUtils.hasText(baseQueryDto.getSn())&& CollectionUtils.isEmpty(baseQueryDto.getSnList())) {
            LocalRequest localRequest = LocalContext.get();
            if (localRequest == null) {
                return;
            }
            if (localRequest instanceof LocalAdminUserRequest) {
                LocalAdminUserRequest localAdminUserRequest = (LocalAdminUserRequest) localRequest;
                baseQueryDto.setSn(localAdminUserRequest.getQuerySn());
                baseQueryDto.setSnList(localAdminUserRequest.getQuerySnList());
            }
            else if (localRequest instanceof LocalMerchantRequest) {
                LocalMerchantRequest merchantRequest = (LocalMerchantRequest) localRequest;
                baseQueryDto.setSn(merchantRequest.getQuerySn());
            }
        }
    }
}
